home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 3.iso / dist / fw_plotutils.idb / usr / freeware / share / pic2plot / macros.pic.z / macros.pic
Text File  |  2002-01-08  |  23KB  |  894 lines

  1. .PS
  2. # 02Mar97: Cleaned up this file.  Removed a bunch of the tcpipiv2-only
  3. #       macros, and deleted those that were never used.
  4. #
  5. # This file defines the handy macros used in the document.
  6. #
  7. arrowwid = 0.0625    # This divisible by 2 (0.03125) has to be a "perfect"
  8.             # size for ditroff.  This value is OK for TranScript on
  9.             # on the LaserWriter (576 units/inch).
  10. #arrowht = 0.125
  11. arrowht = 0.09375
  12. #arrowht = 0.0625
  13. dash_off = 0.2        # default
  14. gap_down = 0.12        # default downward distance in timeline gap
  15. gap_side = 0.04        # default sidewards distance in timeline gap
  16. basef = .375
  17. maxwid = 5.416666
  18. unusedfill = .1        # unused portions of structures
  19. cbase = .256
  20. cindent = .275
  21. v6_hash    = 0.06
  22.  
  23. # Just remove "invis" to see the boxes
  24. define    ibox { box invis }
  25.  
  26. # Client double arrow (left to right on top, right to left below)
  27. define    Carrow    {
  28.     arrow -> right 0.15 from $1 + (-0.15/2,  0.04) wid 0.03 ht 0.05
  29.     arrow <- right 0.15 from $1 + (-0.15/2, -0.04) wid 0.03 ht 0.05
  30. }
  31.  
  32. # Server double arrow (right to left on top, left to right below)
  33. define    Sarrow    {
  34.     arrow <- right 0.15 from $1 + (-0.15/2,  0.04) wid 0.03 ht 0.05
  35.     arrow -> right 0.15 from $1 + (-0.15/2, -0.04) wid 0.03 ht 0.05
  36. }
  37.  
  38. # Right arrow
  39. define    Rarrow    {
  40.     arrow -> right 0.15 from $1 + (-0.15/2,  0.00) wid 0.03 ht 0.05
  41. }
  42.  
  43. # Left arrow
  44. define    Larrow    {
  45.     arrow <- right 0.15 from $1 + (-0.15/2,  0.00) wid 0.03 ht 0.05
  46. }
  47.  
  48. #
  49. # flowdef( <scale> )
  50. # set up default for data flow pictures
  51. define    flowdef X
  52.     boxht = 0.2*$1
  53.     boxwid = 0.8*$1
  54.     ellipsewid = boxwid
  55.     ellipseht = boxht*1.5
  56. .ps 8
  57. .vs 10
  58. X
  59.  
  60. #
  61. # memdef( <maxbytes>, <x-scale>, <y-scale>)
  62. # set up default for memory layout pictures
  63. define    memdef X
  64.     boxht = .3*$3
  65.     boxwid = (.95*maxwid)/$1*$2
  66.     boff = boxwid/(2*$1)
  67.     poff = boxht*.25
  68.     arrowht = .09375*.8
  69.     arrowwid = 0.0625*.8
  70.     labelspace=.4        # used in by field2_a functions
  71. .ps 8
  72. .vs 10
  73. X
  74.  
  75. #
  76. # dsdef
  77. # setup defaults for data structure pictures
  78. define    dsdef X
  79.     boxht = 0.15
  80.     boxwid = boxht*6
  81.     myboxrad = boxht/4
  82.     ellipsewid = boxwid
  83.     ellipseht = boxht*1.5
  84.     arrowwid = 0.0625*.75
  85.     arrowht = 0.09375*.75
  86.     poff = .5*boxht
  87.     # ellipse offset
  88.     eoff = .5*poff
  89. .ps 8
  90. .vs 9
  91. X
  92.  
  93. #
  94. # text_span ( <left-corner>, <right-corner>, <text>, <text-wid>,
  95. #                    <height-of-text-above-corners> )
  96. #
  97. # For normal text, <height...> should be 0.15.
  98. #
  99. define    text_span X
  100. Lab001:    $3 at 1/2 <$1, $2> + (0, $5)
  101.     arrow from Lab001.c + (- $4/2, 0) to $1 + (0, $5)
  102.     arrow from Lab001.c + (  $4/2, 0) to $2 + (0, $5)
  103. X
  104.  
  105. #
  106. # solid_box ( <sw-posn>, <ne-posn> )
  107. #
  108. # Draw a solid box, given 2 opposite corner positions.
  109. # Note - unlike the dash_box macro below, we draw the box exactly from
  110. # from the points specified - we don't offset the box by 0.2i from
  111. # the given coordinates.
  112. # The box is drawn in the order of the arguments, so that the command
  113. # "... at last line.c below" will be positioned at the line from the
  114. # se-posn to the sw-posn.
  115. #
  116. define    solid_box X
  117. S0001: $1
  118. S0002: $2
  119.     line from S0001 to (S0001.x, S0002.y)
  120.     line from last line.end to S0002
  121.     line from last line.end to (S0002.x, S0001.y)
  122.     line from last line.end to S0001
  123. X
  124.  
  125. #
  126. # dash_box ( <sw-posn>, <ne-posn> [ , <optional-dash-length> ] )
  127. #
  128. # Draw a dashed box, given the 2 opposite corner positions.
  129. # The box is drawn in the order of the arguments, so that the command
  130. # "... at last line.c below" will be positioned at the line from the
  131. # se-posn to the sw-posn.
  132. #
  133. # Caller can set "dash_off = <value>" to change the default of 0.2 inches
  134. # from all sides.  This has to be done before each call to the macro,
  135. # as we reset it after each call.
  136. #
  137. # The <optional-dash-length> specifies the length of each dash and the
  138. # length of the space between each dash.  The default is 0.05.
  139. # Note this feature uses pic's substitution of the null string for any
  140. # missing arguments in a macro call.
  141. #
  142. define    dash_box X
  143. S001:    $1
  144. S002:    $2
  145.     line dashed $3 from S001 + (-dash_off, -dash_off) to \
  146.         (S001.x, S002.y) + (-dash_off, dash_off)
  147.     line dashed $3 from last line.end to \
  148.         S002 + (dash_off, dash_off)
  149.     line dashed $3 from last line.end to \
  150.         (S002.x, S001.y) + (dash_off, -dash_off)
  151.     line dashed $3 from last line.end to \
  152.         S001 + (-dash_off, -dash_off)
  153. dash_off = 0.2        # reset default
  154. X
  155.  
  156. #
  157. # left_brace ( <top>, <bottom> )
  158. #
  159. define    left_brace X
  160. LB1:    $1
  161. LB2:    $2
  162.     arc from LB1 + (-0.09375, 0.00) to LB1 + (-0.15625, -0.0625) rad 0.0625
  163.     line down (((LB1.y - LB2.y) - 0.125) / 2) - 0.03125
  164.     line down  0.03125 left 0.03125
  165. Bracept:line right 0.03125 down 0.03125
  166.     line to LB2 + (-0.15625, 0.0625)
  167.     arc from last line.end to LB2 + (-0.09375, 0.00) rad 0.0625
  168. X
  169.  
  170. #
  171. # right_brace ( <top>, <bottom> )
  172. #
  173. define    right_brace X
  174. RB1:    $1
  175. RB2:    $2
  176.     arc cw from RB1 + (0.09375, 0.00) to RB1 + (0.15625, -0.0625) rad 0.0625
  177.     line down (((RB1.y - RB2.y) - 0.125) / 2) - 0.03125
  178.     line down 0.03125 right 0.03125
  179. Bracept:line left 0.03125 down 0.03125
  180.     line to RB2 + (0.15625, 0.0625)
  181.     arc cw from last line.end to RB2 + (0.09375, 0.00) rad 0.0625
  182. X
  183.  
  184. #
  185. # bottom_brace ( <left>, <right> )
  186. #
  187. define    bottom_brace X
  188. BB1:    $1
  189. BB2:    $2
  190.     arc from BB1 + (0.00, -0.09375) to BB1 + (0.0625, - 0.15625) rad 0.0625
  191.     line right (((BB2.x - BB1.x) - 0.125) / 2) - 0.03125
  192.     line right 0.03125 down 0.03125
  193. Bracept:line up 0.03125 right 0.03125
  194.     line to BB2 + (-0.0625, -0.15625)
  195.     arc from last line.end to BB2 + (0, -0.09375) rad 0.0625
  196. X
  197.  
  198. #
  199. # top_brace ( <left>, <right> )
  200. #
  201. define    top_brace X
  202. TB1:    $1
  203. TB2:    $2
  204.     arc cw from TB1 + (0.00, 0.09375) to TB1 + (0.0625, 0.15625) rad 0.0625
  205.     line right (((TB2.x - TB1.x) - 0.125) / 2) - 0.03125
  206.     line right 0.03125 up 0.03125
  207. Bracept:line down 0.03125 right 0.03125
  208.     line to TB2 + (-0.0625, 0.15625)
  209.     arc cw from last line.end to TB2 + (0, 0.09375) rad 0.0625
  210. X
  211.  
  212. #
  213. # line_gap_down ( <top>, <bottom> )
  214. #
  215. define    line_gap_down X
  216. Start:    $1
  217. End:    $2
  218.  
  219.     line down ((Start.y - End.y) - gap_down)/2 from Start
  220.     line right gap_side
  221.     line left gap_side*2 down gap_down
  222.     line right gap_side
  223.     line to End
  224. gap_down = 0.12        # reset default
  225. gap_side = 0.04        # reset default
  226. X
  227.  
  228. #
  229. # line_gap_right ( <left>, <right> )
  230. #
  231. define    line_gap_right X
  232. Start:    $1
  233. End:    $2
  234.  
  235.     line right ((End.x - Start.x) - gap_down)/2 from Start
  236.     line up gap_side
  237.     line down gap_side*2 right gap_down
  238.     line up gap_side
  239.     line to End
  240. gap_down = 0.12        # reset default
  241. gap_side = 0.04        # reset default
  242. X
  243.  
  244. #
  245. # label_above( <sw-posn>, <se-posn>, <arrow-length>, <text> )
  246. #
  247. define    label_above X
  248. P001:    $1 + (0, 0.1)
  249. P002:    $2 + (0, 0.1)
  250.     line up 0.2 from P001
  251.     line up 0.2 from P002
  252.     arrow <- right $3 from P001 + (0, 0.1)
  253.     arrow <- left  $3 from P002 + (0, 0.1)
  254.     $4 at 1/2 <2nd last arrow.start, last arrow.start>
  255. X
  256.  
  257. #
  258. # label_below( <sw-posn>, <se-posn>, <arrow-length>, <text> )
  259. #
  260. define    label_below X
  261. P001:    $1 + (0, -0.1)
  262. P002:    $2 + (0, -0.1)
  263.     line down 0.2 from P001
  264.     line down 0.2 from P002
  265.     arrow <- right $3 from P001 + (0, -0.1)
  266.     arrow <- left  $3 from P002 + (0, -0.1)
  267.     $4 at 1/2 <2nd last arrow.start, last arrow.start>
  268. X
  269.  
  270. #
  271. # text_spanv ( <left-corner>, <right-corner>, <text>, <text-wid>,
  272. #                    <height-of-text-above-corners> )
  273. # end points are in line with text
  274. #
  275. define    text_spanv X
  276. Lab001:    $3 at 1/2 <$1, $2> 
  277.     arrow from Lab001.c + (0, - $4/2) to $1
  278.     arrow from Lab001.c + (0,  $4/2) to $2
  279. X
  280.  
  281. #
  282. # text_spanc ( <left-corner>, <right-corner>, <text>, <text-wid>,
  283. #                    <height-of-text-above-corners> )
  284. # end points are in line with text
  285. #
  286. define    text_spanc X
  287. Lab001:    $3 at 1/2 <$1, $2> 
  288.     arrow from Lab001.c + (- $4/2, 0) to $1
  289.     arrow from Lab001.c + (  $4/2, 0) to $2
  290. X
  291.  
  292.  
  293. #
  294. # measureb ( sw-corner, se-corner, text, <text-wid>, <height>)
  295. # Show the measurement below the object
  296. define    measureb X
  297.     Mleft: line from $1 + (0, -0.05) to $1 + (0, -($5 * 1.5) )
  298.     Mright: line from $2 + (0, -0.05) to $2 + (0, -($5 * 1.5) )
  299.     text_spanc( Mleft.c, Mright.c, $3, $4, $5)
  300. X
  301.  
  302. #
  303. # measurea ( sw-corner, se-corner, text, <text-wid>, <height>)
  304. # Show the measurement above the object
  305. define    measurea X
  306.     Mleft: line from $1 + (0, 0.05) to $1 + (0, ($5 * 1.5) )
  307.     Mright: line from $2 + (0, 0.05) to $2 + (0, ($5 * 1.5) )
  308.     text_spanc( Mleft.c, Mright.c, $3, $4, $5)
  309. X
  310.  
  311. #
  312. # measurel ( nw-corner, sw-corner, text, <text-wid>, <height>)
  313. # Show the measurement above the object
  314. define    measurel X
  315.     Mtop: line from $1 - (0.05, 0) to $1 - (($5 * 1.5),0 )
  316.     Mbot: line from $2 - (0.05, 0) to $2 - (($5 * 1.5),0 )
  317.     text_spanv( Mtop.c, Mbot.c, $3, $4, $5)
  318. X
  319.  
  320. #
  321. # measurer ( nw-corner, sw-corner, text, <text-wid>, <height>)
  322. # Show the measurement above the object
  323. define    measurer X
  324.     Mtop: line from $1 + (0.05, 0) to $1 + (($5 * 1.5),0 )
  325.     Mbot: line from $2 + (0.05, 0) to $2 + (($5 * 1.5),0 )
  326.     text_spanv( Mtop.c, Mbot.c, $3, $4, $5)
  327. X
  328.  
  329. #
  330. # queue ( <start> )
  331. #
  332. define    queue X
  333. $2: $1 - (.1,0)
  334. $2exit: $1 + (0,.1)
  335.     box wid 0.20 ht 0.05 with .nw at $2
  336.     box wid 0.20 ht 0.05 with .nw at last box.sw
  337.     box wid 0.20 ht 0.05 with .nw at last box.sw
  338.     box wid 0.20 ht 0.05 with .nw at last box.sw
  339.     line from last box.sw down 0.20
  340.     line from last box.se down 0.20
  341. $2entry: last box.s - 0,0.1
  342.     move to $2
  343. X
  344.  
  345. #
  346. # pointer (from, to, sx, sy)
  347. #
  348. define    pointer X
  349. # We want a 10% curve
  350. Start: $1
  351. End: $2
  352.     dx = End.x - Start.x
  353.     dy = End.y - Start.y
  354.     incx = dx * $3; incy = dy * $4
  355.  
  356.     spline -> from $1 \
  357.         to $1 + ( -incx, incy ) \
  358.         to $2 + ( incx, -incy ) \
  359.         to $2
  360. X
  361.  
  362. #
  363. # field_a( text, bytes, label, other)
  364. # draw a box but label it above the field 
  365. # leave room for other labels that may be there
  366. define    field_a X
  367.     $3: box wid (boxwid*$2)
  368.         sprintf("%.0f", $2) below at last box.s
  369.         spline <- from $3.n up (2+$4)*.4*boxht then right .1
  370.         $1 at last spline.end ljust
  371.         move to $3.e
  372. X
  373.  
  374. #
  375. # field_s(text, bytes, label)
  376. # Draw a field with a slanted label
  377. # leave room for other labels that may be there
  378. define    field_s X
  379.     $3: box wid (boxwid*$2)
  380.         sprintf("%.0f", $2) below at last box.s
  381.         line invis $1 ljust above aligned \
  382.             from $3.ne + (-.75*boxwid,-.5*boxht) up boxht right boxwid 
  383.         move to $3.e
  384. X
  385.  
  386. #
  387. # field2_ai( opts, text, sizetext, bytes, label, other)
  388. # draw an box with options but label it above the field 
  389. # leave room for other labels that may be there
  390. # any text for the bottom is provided by sizetext
  391. # additional box options can be provided in opts
  392.  
  393. define    field2_ai X
  394.     $5: box $1 wid (boxwid*$4)
  395.         spline <- from $5.n up (1.25+$6)*labelspace*boxht then right .1
  396.         $2 at last spline.end ljust
  397.         $3 below at $5.s
  398.         move to $5.e
  399. X
  400.  
  401. #
  402. # field2_al( text, sizetext, bytes, label, other)
  403. # draw a box but label it above the field but to the left
  404. # leave room for other labels that may be there
  405. # any text for the bottom is provided by sizetext
  406.  
  407. define    field2_al X
  408.     $4: box wid (boxwid*$3)
  409.         spline <- from $4.n up (1.25+$5)*labelspace*boxht then left .1
  410.         right
  411.         $1 at last spline.end rjust
  412.         $2 below at $4.s
  413.         move to $4.e
  414. X
  415.  
  416. #
  417. # field2_a( text, sizetext, bytes, label, other)
  418. # draw a box but label it above the field 
  419. # leave room for other labels that may be there
  420. # any text for the bottom is provided by sizetext
  421.  
  422. define    field2_a X
  423.     $4: box wid (boxwid*$3)
  424.         spline <- from $4.n up (1.25+$5)*labelspace*boxht then right .1
  425.         $1 at last spline.end ljust
  426.         $2 below at $4.s
  427.         move to $4.e
  428. X
  429.  
  430. # draw a box and label it as a field within a packet
  431. # field( boxtext, units, label )
  432. define    field X
  433.     $3: box $1 wid (boxwid*$2)
  434.         move to $3.e
  435. X
  436.  
  437. # draw a box and label it as a field within a packet
  438. # the size in bytes appears below the box
  439. # field2( boxtext, sizetext, units, boxlabel)
  440. define    field2 X
  441.     $4: box $1 wid (boxwid*$3)
  442.         $2 below at last box.s
  443.         move to $4.e
  444. X
  445.  
  446. # Show field with internal tick marks
  447. # fieldt( scale, text, units, label )
  448. define    fieldt X
  449.     fw = basef * $1
  450.     fh = basef
  451.     $4: box $2 wid (fw*$3) ht fh
  452.     for t = fw to fw * ($3 - 1) by fw do {
  453.         line from $4.nw + (t,0) to $4.sw + (t,0) dotted
  454.     }
  455.     move to $4.e
  456. #    [ "$3" at $4.s below ]
  457. X
  458.  
  459. define    inetsw X
  460. Inetsw: box "-" with .c at $1; "0 " rjust at last box.w
  461. "\fCinetsw[]\fP" above at last box.n
  462. Iudp: box "UDP" with .n at last box.s; "1 " rjust at last box.w
  463. Itcp: box "TCP" with .n at last box.s; "2 " rjust at last box.w
  464. Iicmp: box "ICMP" with .n at last box.s; "3 " rjust at last box.w
  465. Irip: box "raw IP" with .n at last box.s; "4 " rjust at last box.w
  466. box "raw IP" with .n at last box.s; "5 " rjust at last box.w
  467. X
  468.  
  469. #
  470. # array( count, text, center0)
  471. define    array X
  472. A0: box with .nw at $3 ; $2 above at last box.n
  473. for i = 2 to $1 do {
  474.     Al: box with .n at last box.s;
  475. }
  476. X
  477.  
  478. #
  479. # lnullp( start )
  480. # draw the grounding end of a null pointer but on the left
  481. define    lnullp X
  482.     spline from $1+(poff,0) left 2*poff+boxht/2 then down boxht
  483.     Mid: Here
  484.     line from Mid - (boxht/2, 0) right boxht
  485.     line from Mid - (boxht/4,.02) right boxht/2
  486.     line from Mid - (boxht/8,.04) right boxht/4
  487.     line from Mid - (boxht/16,.06) right boxht/8
  488.     #pstart($1 + (poff,0))
  489. X
  490.  
  491. #
  492. # dnullp(start)
  493. # draw the grounding end of a null pointer
  494. define    dnullp X
  495.     line from $1 down boxht
  496.     Mid: Here
  497.     line from Mid - (boxht/2, 0) right boxht
  498.     line from Mid - (boxht/4,.02) right boxht/2
  499.     line from Mid - (boxht/8,.04) right boxht/4
  500.     line from Mid - (boxht/16,.06) right boxht/8
  501. X
  502.  
  503. #
  504. # nullp( start, horiz )
  505. # draw the grounding end of a null pointer
  506. define    nullp X
  507.     if ($2 == 0) then {horiz=boxht/2} else { horiz=$2 }
  508.     #horiz=$2
  509.     spline from $1-(poff,0) right 2*poff+horiz then down boxht
  510.     Mid: Here
  511.     line from Mid - (boxht/2, 0) right boxht
  512.     line from Mid - (boxht/4,.02) right boxht/2
  513.     line from Mid - (boxht/8,.04) right boxht/4
  514.     line from Mid - (boxht/16,.06) right boxht/8
  515.     #pstart($1-(poff,0))
  516. X
  517.  
  518. #
  519. # vv_spline(top, bottom, offset, gap, arrow )
  520. # Draw a V shaped spline from top to bottom.
  521. define    vv_spline X
  522.     initspline($1, $2, .5, .5, .25)
  523.     line from Spline1 right $3
  524.     spline from Spline1 then right $4 then to Spline2 $5
  525. X
  526.     
  527. #
  528. # vu_spline(top, bottom, off, off, gap, arrow, text)
  529. # Connect top and bottom on the left
  530. define    vu_spline X
  531.     initspline($1, $2+($5,0), .5, .5, .25)
  532. #        then up yrad then up dy-2*yrad then up yrad 
  533.     spline from Spline1 then right dx-xrad then right xrad \
  534.         then up dy \
  535.         then left xrad then left dx-xrad $6
  536.     if ($3 != 0 ) then { 
  537.         line from Spline1 right $3 
  538.         #circle fill 1 rad .015 with .c at last line.end
  539.     }
  540.     if ($4 != 0 ) then { 
  541.         line from Spline2 right $4 
  542.         #circle fill 1 rad .015 with .c at last line.end
  543.     }
  544.     line invis from $1 + ($5,0) then up dy $7
  545. X
  546.  
  547. #
  548. # hu_spline(left, right, off, off, gap, arrow, text)
  549. # Connect left and right horizontally
  550. define    hu_spline X
  551.     Spline1: $1
  552.     Spline2: $2
  553.     dx = Spline2.x - Spline1.x
  554.     spline from Spline1 then up $5 then right dx/2 \
  555.         then to Spline2 + (0,$5) then to Spline2 $6
  556.     if ($3 != 0 ) then { line from Spline1 up $3 }
  557.     if ($4 != 0 ) then { line from Spline2 up $4 }
  558.     line invis from $1 + (0,$5) then right dx $7
  559. X
  560.  
  561. #
  562. # initspline(p1, p2, scalex, scaley, scale_radius)
  563. define    initspline X
  564.     Spline1: $1
  565.     Spline2: $2
  566.     dx = Spline2.x - Spline1.x
  567.     dy = Spline2.y - Spline1.y
  568.     if (dx < 0 ) then { adx = -dx} else { adx = dx}
  569.     if (dy < 0 ) then { ady = -dy} else { ady = dy }
  570.     srad = max(min(adx*$3, ady*$4), boxht*$5)
  571.     #srad = boxht/4
  572.     xrad = srad
  573.     yrad = srad
  574.     #xrad = adx*$3
  575.     #yrad = ady*$4
  576.     #sprintf("dx %f dy %f srad %fxrad %f yrad %f", dx, dy, srad, xrad, yrad) \
  577.     #    above at Spline1
  578.     if (dx < 0 ) then { xrad = -srad }
  579.     if (dy < 0 ) then { yrad = -srad }
  580.     #if (dx < 0 ) then { xrad = -xrad }
  581.     #if (dy < 0 ) then { yrad = -yrad }
  582. X
  583.  
  584. #
  585. # lr_spline(start, end, off, off, arrow, text, rad)
  586. # Connect start and end in an l shape
  587. define    lr_spline X
  588.     initspline($1, $2, .2, .2, $7)
  589.     spline from Spline1 \
  590.         then up dy-yrad \
  591.         then up yrad \
  592.         then right xrad \
  593.         then right dx-xrad $5
  594.     if ($3 != 0 ) then { line from Spline1 up $3 }
  595.     if ($4 != 0 ) then { line from Spline2 right $4 }
  596.     line invis from $1 + (0,dy) then right dx $6
  597. X
  598.  
  599. #
  600. # l_spline(start, end, off, off, arrow, text)
  601. # Connect start and end in an l shape
  602. define    l_spline X
  603.     initspline($1, $2, .2, .2, 1.25)
  604.     spline from Spline1 \
  605.         then up dy-yrad \
  606.         then up yrad \
  607.         then right xrad \
  608.         then right dx-xrad $5
  609.     if ($3 != 0 ) then { line from Spline1 up $3 }
  610.     if ($4 != 0 ) then { line from Spline2 right $4 }
  611.     line invis from $1 + (0,dy) then right dx $6
  612. X
  613.  
  614. #
  615. # vertical spline
  616. # v_spline(p1, p2, off1, off2, arrow, turn)
  617. #
  618. define    v_spline X
  619.     vz_spline($1, $2, $3, $4, $5, $6, .05)
  620. #    initspline($1, $2, .2, .2)
  621. #    spline from Spline1 \
  622. #        then up (dy*$6)-yrad then up yrad \
  623. #        then right dx then up yrad \
  624. #        then up (dy*(1-$6))-yrad $5
  625. #    if ($3 != 0 ) then { line from Spline1 down $3 }
  626. #    if ($4 != 0 ) then { line from Spline2 up $4 }
  627. X
  628.  
  629. #
  630. # vertical Z spline
  631. # vz2_spline(p1, p2, off1, off2, arrow, turn, overrun)
  632. # same as hz_spline but with absolute measurement for turn
  633. # instead of a percentage
  634. #
  635. define    vz2_spline X
  636.     initspline($1, $2, .2, .2, .25)
  637.     d1=$6
  638.     d2=dy-$6
  639.     overrun=$7
  640.     span=min(min(.9*max(d1, -d1), .9*max(d2, -d2)), max($7, -$7))
  641.     sign=dy/(max(dy,-dy))
  642.     if (overrun < 0 ) then {
  643.         overrun = -.5*span
  644.     }
  645.     spline from Spline1 \
  646.         then up $6 - span*sign \
  647.         then up span*sign + overrun*sign \
  648.         then right dx up 2*overrun*sign \
  649.         then up overrun*sign + span*sign \
  650.         then to Spline2 $5
  651.     if ($3 != 0 ) then { line from Spline1 down $3 }
  652.     if ($4 != 0 ) then { line from Spline2 up $4 }
  653. X
  654.  
  655. #
  656. # vertical Z spline
  657. # vz_spline(p1, p2, off1, off2, arrow, turn, overrun)
  658. #
  659. define    vz_spline X
  660.     overrun=$7
  661.     if (overrun == 0 ) then { overrun = .2 }
  662.     initspline($1, $2, .2, .05, .25)
  663.     spline from Spline1 \
  664.         then up yrad then (dy*$6)+dy*overrun-yrad \
  665.         then right dx down 2*dy*overrun \
  666.         then up (dy*(1-$6))+dy*overrun-yrad then up yrad $5
  667.     if ($3 != 0 ) then { line from Spline1 down $3 }
  668.     if ($4 != 0 ) then { line from Spline2 up $4 }
  669. X
  670.  
  671. #
  672. # horizontal Z spline
  673. # hz_spline(p1, p2, off1, off2, arrow, turn, overrun)
  674. #
  675. define    hz_spline X
  676.     overrun=$7
  677.     if (overrun == 0 ) then { overrun = .2 }
  678.     initspline($1, $2, .2, .2, .25)
  679.     spline from Spline1 \
  680.         then right (dx*$6)+dx*overrun \
  681.         then up dy left 2*dx*overrun \
  682.         then right dx*(1-$6)+dx*overrun $5
  683.     if ($3 != 0 ) then { line from Spline1 left $3 }
  684.     if ($4 != 0 ) then { line from Spline2 right $4 }
  685. X
  686.  
  687. #
  688. # erase(center, fill, rad)
  689. #
  690. define    erase X
  691.     if ( $3 == 0 ) then { erad = boxht/8 } else { erad = $3 }
  692.     circle invis rad erad fill $2 with .c at $1
  693. X
  694.  
  695. #
  696. # target(center)
  697. #
  698. define    target X
  699.     circle rad boxht/2 with .c at $1
  700. X
  701.  
  702. # spline down and on the left
  703. define    spline_dl {
  704. Start:  $1
  705. Dest:   $2
  706.     line from Start to Start + ($3, 0)
  707.         spline $5 from Start \
  708.                 then left $4 \
  709.                 then down $4 \
  710.                 then to Dest + (-$4, $4) \
  711.                 then to Dest + (-$4, 0) \
  712.                 then to Dest
  713. }
  714.  
  715. # spline down and on the right
  716. define    spline_dr {
  717. Start:  $1
  718. Dest:   $2
  719.     line from Start to Start + ($3, 0)
  720.         spline $5 from Start \
  721.                 then right $4 \
  722.                 then down $4 \
  723.                 then to Dest + ( $4, $4) \
  724.                 then to Dest + ( $4, 0) \
  725.                 then to Dest
  726. }
  727.  
  728. # spline up and on the left
  729. define    spline_ul {
  730. Start:  $1
  731. Dest:   $2
  732.     line from Start to Start + ($3, 0)
  733.         spline $5 from Start \
  734.                 then left $4 \
  735.                 then up $4 \
  736.                 then to Dest + (-$4, -$4) \
  737.                 then to Dest + (-$4, 0) \
  738.                 then to Dest
  739. }
  740.  
  741. # spline up and on the right
  742. define    spline_ur {
  743. Start:  $1
  744. Dest:   $2
  745.     line from Start to Start + ($3, 0)
  746.         spline $5 from Start \
  747.                 then right $4 \
  748.                 then up $4 \
  749.                 then to Dest + ( $4, -$4) \
  750.                 then to Dest + ( $4, 0) \
  751.                 then to Dest
  752. }
  753.  
  754. # Spline right/up/right
  755. define    spline_rur {
  756. Start:    $1
  757. End:    $2
  758.     if ($4 == 0) then { dx = (End.x - Start.x) / 2 } else { dx = $4 }
  759.     if ("$6" != "") then { turn1rad = $6 } else { turn1rad = 0.2 }
  760.     if ("$7" != "") then { turn2rad = $7 } else { turn2rad = 0.2 }
  761. Turn1:    (Start.x + dx, Start.y)
  762. Turn2:    (Start.x + dx, End.y)
  763.     line from Start to Start + ($3, 0)
  764.     spline $5 from Start \
  765.         to Turn1 + (-turn1rad, 0) \
  766.         to Turn1 \
  767.         to Turn1 + (0,  turn1rad) \
  768.         to Turn2 + (0, -turn2rad) \
  769.         to Turn2 \
  770.         to Turn2 + ( turn2rad, 0) \
  771.         to End
  772. }
  773.  
  774. # Spline right/down/right
  775. define    spline_rdr {
  776. Start:    $1
  777. End:    $2
  778.     if ($4 == 0) then { dx = (End.x - Start.x) / 2 } else { dx = $4 }
  779.     if ("$6" != "") then { turn1rad = $6 } else { turn1rad = 0.2 }
  780.     if ("$7" != "") then { turn2rad = $7 } else { turn2rad = 0.2 }
  781. Turn1:    (Start.x + dx, Start.y)
  782. Turn2:    (Start.x + dx, End.y)
  783.     line from Start to Start + ($3, 0)
  784.     spline $5 from Start \
  785.         to Turn1 + (-turn1rad, 0) \
  786.         to Turn1 \
  787.         to Turn1 + (0, -turn1rad) \
  788.         to Turn2 + (0,  turn2rad) \
  789.         to Turn2 \
  790.         to Turn2 + ( turn2rad, 0) \
  791.         to End
  792. }
  793.  
  794. # Spline left/up/left
  795. define    spline_lul {
  796. Start:    $1
  797. End:    $2
  798.     if ($4 == 0) then { dx = (Start.x - End.x) / 2 } else { dx = $4 }
  799.     if ("$6" != "") then { turn1rad = $6 } else { turn1rad = 0.2 }
  800.     if ("$7" != "") then { turn2rad = $7 } else { turn2rad = 0.2 }
  801. Turn1:    (Start.x - dx, Start.y)
  802. Turn2:    (Start.x - dx, End.y)
  803.     line from Start to Start + ($3, 0)
  804.     spline $5 from Start \
  805.         to Turn1 + ( turn1rad, 0) \
  806.         to Turn1 \
  807.         to Turn1 + (0,  turn1rad) \
  808.         to Turn2 + (0, -turn2rad) \
  809.         to Turn2 \
  810.         to Turn2 + (-turn2rad, 0) \
  811.         to End $5
  812. }
  813.  
  814. # Spline left/down/left
  815. define    spline_ldl {
  816. Start:    $1
  817. End:    $2
  818.     if ($4 == 0) then { dx = (Start.x - End.x) / 2 } else { dx = $4 }
  819.     if ("$6" != "") then { turn1rad = $6 } else { turn1rad = 0.2 }
  820.     if ("$7" != "") then { turn2rad = $7 } else { turn2rad = 0.2 }
  821. Turn1:    (Start.x - dx, Start.y)
  822. Turn2:    (Start.x - dx, End.y)
  823.     line from Start to Start + ($3, 0)
  824.     spline $5 from Start \
  825.         to Turn1 + ( turn1rad, 0) \
  826.         to Turn1 \
  827.         to Turn1 + (0, -turn1rad) \
  828.         to Turn2 + (0,  turn2rad) \
  829.         to Turn2 \
  830.         to Turn2 + (-turn2rad, 0) \
  831.         to End $5
  832. }
  833.  
  834. # Place hash marks at the 32-bit boundaries of an IPv6 16-byte address.
  835.  
  836. define    ipv6_hash {
  837. NW:    $1.nw
  838. SE:    $1.se
  839. mywid    = SE.x - NW.x
  840. myht    = NW.y - SE.y
  841.     line right v6_hash from NW + (0, -1*myht/4)
  842.     line right v6_hash from NW + (0, -2*myht/4)
  843.     line right v6_hash from NW + (0, -3*myht/4)
  844.     line left  v6_hash from SE + (0,  1*myht/4)
  845.     line left  v6_hash from SE + (0,  2*myht/4)
  846.     line left  v6_hash from SE + (0,  3*myht/4)
  847. v6_hash    = 0.06        # reset default
  848. }
  849.  
  850. # Draw routers with rounded corners.
  851. # Problem with boxes with rounded corners: .ne, .ne, .se, .sw now refer to
  852. # the rounded portion, which screws things up.  Make invisible box without
  853. # rounded corners for compass positions.
  854.  
  855. define  router {
  856.     box invis $1 $2
  857.     box rad 0.1 with .n at last box.n
  858. }
  859.  
  860. # small15_text2(box_name, top_string, bottom_string)
  861. #
  862. # Text within a box is often "too big".  For example: box "top" "bottom"
  863. # can have the string "top" too high in the box (with ascenders
  864. # touching the top of the box) and the string "bottom" can be too low
  865. # (with descenders touching the bottom of the box.
  866. # But placing .ps and .vs commands within a picture is asking for trouble.
  867. # The "right" way to do this is to make the string smaller with an inline
  868. # \s-1 or \s-2, with a vertical motion before and after, then \s0.
  869. #
  870. # The "15" means the vertical motion is 0.15m and the "2" means two arguments.
  871. #
  872. # Note that when invoking this macro, do *not* put the arguments
  873. # top_string and bottom_string in double quotes.  These two arguments
  874. # may contain spaces (but not commas).
  875.  
  876. define    small15_text2 {
  877.     box invis ht $1.ht wid $1.wid with .n at $1.n \
  878.         "\v'0.15m'\s-1$2\s0\v'-0.15m'" "\v'-0.15m'\s-1$3\s0\v'0.15m'"
  879. }
  880.  
  881. # Add invisible space to the right, normally to center picture.
  882.  
  883. define  right_space {
  884.     box invis wid $2 with .w at $1
  885. }
  886.  
  887. # Add invisible space to the right, normally to center picture.
  888.  
  889. define  left_space {
  890.     box invis wid $2 with .e at $1
  891. }
  892.  
  893. .PE
  894.